/**
 * 
 */
package org.apache.struts.register.action;

import java.util.ArrayList;

import org.apache.struts.register.model.Person;
import org.apache.struts.register.model.State;
import org.apache.struts.register.service.EditService;

import com.opensymphony.xwork2.ActionSupport;

/**
 * 
 * @author wanghy
 * @since 2014-2-26
 * 
 */
public class EditAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Person personBean;
	
	private String[] sports = {"football", "baseball", "basketball"};
	
	private String[] genders = {"male", "female", "not sure"};
	
	private String[] abbrs = {"AZ", "CA", "FL", "KS", "NY"};
	
	private String[] names = {"Arizona", "California", "Florida", "Kansas", "New York"};
	
	private String[] carModelsAvailable = {"Ford", "Chrysler", "Toyota", "Nissan"};
	
	private ArrayList<State> states;
	
	private EditService editService;
	
	@Override
	public String execute() throws Exception {
		//save
		editService.savePerson(personBean);
		return SUCCESS;
	}
	
	@Override
	public String input() throws Exception {
		personBean = editService.getPerson();
		return INPUT;
	}

	/**
	 * @return the personBean
	 */
	public Person getPersonBean() {
		return personBean;
	}

	/**
	 * @param personBean
	 *            the personBean to set
	 */
	public void setPersonBean(Person personBean) {
		this.personBean = personBean;
	}

	/**
	 * @return the sports
	 */
	public String[] getSports() {
		return sports;
	}

	/**
	 * @return the genders
	 */
	public String[] getGenders() {
		return genders;
	}

	/**
	 * @return the states
	 */
	public ArrayList<State> getStates() {
		states = new ArrayList<State>();
		int i = 0;
		for (String abbr : abbrs) {
			State state = new State(abbr, names[i++]);
			states.add(state);
		}
		return states;
	}

	/**
	 * @return the carModelsAvailable
	 */
	public String[] getCarModelsAvailable() {
		return carModelsAvailable;
	}

	/**
	 * @param editService the editService to set
	 */
	public void setEditService(EditService editService) {
		this.editService = editService;
	}

}
